$(document).ready(function() {
	dates1 = $( "#from1, #to1" ).datepicker({
			changeMonth: true,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "from1" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates1.not( this ).datepicker( "option", option, date );
			}
	});
	$( "#from1, #to1" ).datepicker($.datepicker.regional[ 'zh-CN'] );

	dates2 = $( "#from2, #to2" ).datepicker({
		changeMonth: true,
		numberOfMonths: 1,
		onSelect: function( selectedDate ) {
			var option = this.id == "from2" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates2.not( this ).datepicker( "option", option, date );
		}
	});
	$( "#from2, #to2" ).datepicker($.datepicker.regional[ 'zh-CN'] );
	
	dates3 = $( "#from3, #to3" ).datepicker({
		changeMonth: true,
		numberOfMonths: 1,
		onSelect: function( selectedDate ) {
			var option = this.id == "from3" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates3.not( this ).datepicker( "option", option, date );
		}
	});
	$( "#from3, #to3" ).datepicker($.datepicker.regional[ 'zh-CN'] );
	
	$("#searchSummaryBtn").click(function(){
		
		var from = $("#from1").val();
		var to = $("#to1").val();
		if(from=="" || to==""){
			alert("请先选择日期");
		}else{
			$.getJSON(getRootPath()+ "/MainMenu/members/comprehensiveStatistics.htm", $("#summarySearchForm").serializeArray() , function(json){
				$("#addMemberCount").html(json.memberSummary.memberCount);
				$("#totalMemberCount").html(json.memberSummary.totalMemberCount);
				$("#costAmount").html(json.memberSummary.cost);
				$("#totalCostAmount").html(json.memberSummary.totalCost);
				$("#selledCount").html(json.memberSummary.selledGoodsCount);
				$("#totalSelledCount").html(json.memberSummary.totalSelledGoodsCount);
			});
		}
	});
	
	$("#searchMemberGoodsCostBtn").click(function(){
		var from = $("#from2").val();
		var to = $("#to2").val();
		if(from=="" || to==""){
			alert("请先选择日期");
		}else{
			$("#memberGoodsCostTable").html("");
			$("#memberCostPageIndex").val("1");
			$("#memberGoodsCostTable").load(getRootPath()+ "/MainMenu/members/memberGoodsCost.htm", $("#memberGoodsCostForm").serializeArray());
		}
	});
	
	$("#goodsStatisticsSearchBtn").click(function(){
		var from = $("#from3").val();
		var to = $("#to3").val();
		if(from=="" || to==""){
			alert("请先选择日期");
		}else{
			$("#goodsStatisticsTable").html("");
			$("#goodsStatisticsPageIndex").val("1");
			$("#goodsStatisticsTable").load(getRootPath()+ "/MainMenu/members/goodsStatistics.htm", $("#goodsStatisticsSearchForm").serializeArray());
		}
	});
});